package com.be.beadmin.basicData.entity;

import com.be.beadmin.common.entity.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import net.bytebuddy.build.ToStringPlugin;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * @author chenwei
 * @date 2/24/2023 3:43 PM
 * User移植
 */
@Entity
@Getter
@Setter
@Table(name="SYS_USER")
public class User extends BaseEntity {
    /**
     * 用户名称
     */
    @Column(name = "NAME",columnDefinition = "VARCHAR(30) COMMENT '名称' ")
    private String name;

    /**
     * 昵称
     */
    @Column(name = "NICK_NAME",columnDefinition = "VARCHAR(30) COMMENT '昵称' ")
    private String nickName;

    /**
     * 密码
     */
    @Column(name = "PASSWORD",columnDefinition = "VARCHAR(200) COMMENT '密码' ")
    private String password;
    /**
     * 用户是否锁定 1.锁定 0.未锁定
     */
    @Column(name = "IS_LOCKED")
    private Boolean locked;

    /**
     * 电子邮箱
     */
    @Column(name = "EMAIL",columnDefinition = "VARCHAR(30) COMMENT '电子邮箱' ")
    private String email;

    /**
     * 手机号
     */
    @Column(name = "PHONE",columnDefinition = "VARCHAR(20) COMMENT '手机登录' ")
    private String phone;

    /**
     * 性别
     */
    @Column(name = "GENDER",columnDefinition = "VARCHAR(20) COMMENT '性别' ")
    private String gender;

    /**
     * 头像
     */
    @Column(name = "AVATAR_NAME",columnDefinition = "VARCHAR(20) COMMENT '头像' ")
    private String avatarName;

    /**
     * 头像地址
     */
    @Column(name = "AVATAR_PATH",columnDefinition = "VARCHAR(20) COMMENT '头像地址' ")
    private String avatarPath;


    private Boolean online = false;

    // 最后一次访问时间
    private Date lastAccessTime ;


    private Boolean allowMulti = false;

    @Column(name = "Token",columnDefinition = "text COMMENT 'Token存储' ")
    private String token;


    /**
     * 绑定User关系
     */
    @JsonManagedReference(value = "roles")
    @ManyToMany(
//            targetEntity = Role.class, cascade = CascadeType.ALL,
            fetch= FetchType.LAZY)
    @JoinTable(name = "SYS_USER_ROLE",
            joinColumns = @JoinColumn(name = "USER_ID"),
            inverseJoinColumns = @JoinColumn(name = "ROLE_ID"))
    private Set<Role> roles = new HashSet<>();


    // 是否是系统用户
    @Column(name = "IS_SYSTEM")
    private Boolean system = false;


    @OneToOne
    @JoinColumn(name = "org_id")
    @ApiModelProperty(value = "用户部门")
    private Organization organization;


}
